﻿//Two dimensional numeric array
namespace Diplom.NumericArrays
{
    using System;

    public class Numeric2DArray
    {
        #region Fields

        /// <summary>
        /// Numeric matrix
        /// </summary>
        Double[][] raw;

        /// <summary>
        /// min, max
        /// </summary>
        double _min, _max;

        /// <summary>
        /// Frequency interval
        /// </summary>
        double Amin, Amax;

        /// <summary>
        /// Time interval
        /// </summary>
        double Bmin, Bmax;

        #endregion

        #region Methods

        /// <summary>
        /// Constructor
        /// </summary>
        public Numeric2DArray()
        {
            raw = new Double[100][];
            for (int i=0;i<raw.Length;i++)
                raw[i] = new Double[100];
            _min = Double.MaxValue;
            _max = Double.MinValue;
            Amin = Bmax = 1;
            Bmin = 0;
            Amax = 2;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="n">size of dimensional 1</param>
        /// <param name="m">size of dimensional 2</param>
        public Numeric2DArray(int n, int m)
        {
            raw = new Double[n][];
            for (int i = 0; i < raw.Length; i++)
                raw[i] = new Double[m];
            _min = Double.MaxValue;
            _max = Double.MinValue;
            Amin = Bmax = 1;
            Bmin = 0;
            Amax = 2;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="n">size of dimensional 1</param>
        public Numeric2DArray(int n)
        {
            raw = new Double[n][];
            _min = Double.MaxValue;
            _max = Double.MinValue;
            Amin = Bmax = 1;
            Bmin = 0;
            Amax = 2;
        }

        /// <summary>
        /// SetLength
        /// </summary>
        /// <param name="row"></param>
        /// <param name="len"></param>
        public void Setlength(int row, int len)
        {
            raw[row] = new double[len];
        }

        /// <summary>
        /// Find Extremum
        /// </summary>
        public void InitCharacters()
        {
            for (int i = 0; i < raw.Length; i++)
            {
                for (int j = 0; j < raw[i].Length; j++)
                {
                    _min = Math.Min(_min, raw[i][j]);
                    _max = Math.Max(_max, raw[i][j]);
                }
            }
        }

        /// <summary>
        /// Insert value
        /// </summary>
        public void Insert(int i,int j, double item)
        {
            raw[i][j] = item;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Minimum
        /// </summary>
        public Double Min
        {
            get
            {
                return _min;
            }
            
        }

        /// <summary>
        /// Maximum
        /// </summary>
        public Double Max
        {
            get
            {
                return _max;
            }

        }

        /// <summary>
        /// Size of first dimension
        /// </summary>
        public int NSize
        {
            get
            {
                return raw.Length;
            }
        }

        /// <summary>
        /// Size of second dimension
        /// </summary>
        public int MSize
        {
            get
            {
                if (raw.Length > 0)
                {
                    return raw[0].Length;
                }
                else
                {
                    return 0;
                }
            }
        }
   
        /// <summary>
        /// Data
        /// </summary>
        public Double[][] Items
        {
            get
            {
                return raw;
            }
            set
            {
                raw = value;
            }
        }

        /// <summary>
        /// Begin of time interval
        /// </summary>
        public Double MinTime
        {
            get
            {
                return Bmin;
            }
            set
            {
                Bmin = value;
            }
        }

        /// <summary>
        /// End of time interval
        /// </summary>
        public Double MaxTime
        {
            get
            {
                return Bmax;
            }
            set
            {
                Bmax = value;
            }
        }

        /// <summary>
        /// Begin of frequency interval
        /// </summary>
        public Double MinFreak
        {
            get
            {
                return Amin;
            }
            set
            {
                Amin = value;
            }
        }

        /// <summary>
        /// End of frequency interval
        /// </summary>
        public Double MaxFreak
        {
            get
            {
                return Amax;
            }
            set
            {
                Amax = value;
            }
        }

        #endregion



    }
}
